package card;

import java.util.*;

public class CardBox {
    public static final String[] suits = {"♥️", "♠️", "⬛️", "♣️"};

    public static List<Card> makeCard() {
        List<Card> cardList = new ArrayList<>(52);
        for (int i = 0; i < 4; i++) {
            for (int j = 1; j <= 13; j++) {
                int rank = j;
                String suit = suits[i];
                Card card = new Card(rank, suit);
                cardList.add(card);
            }
        }
        return cardList;
    }


    public static void shuffle(List<Card> cardList) {
        for (int i = cardList.size() - 1; i > 0; i--) {
            int randomIndex = new Random().nextInt(i);
            swap(cardList,randomIndex,i);
        }
    }

    private static void swap(List<Card> cardList, int i, int j){
        Card tmp = cardList.get(i);
        cardList.set(i,cardList.get(j));
        cardList.set(j,tmp);
    }

    public void drawCard (List<Card> cardList){
        List<Card> hand1 = new ArrayList<>();
        List<Card> hand2 = new ArrayList<>();
        List<Card> hand3 = new ArrayList<>();

        List<List<Card>> hands = new ArrayList<>();
        hands.add(hand1);
        hands.add(hand2);
        hands.add(hand3);

        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 3; j++) {
                hands.get(j).add(cardList.remove(0));
            }
        }
        for (int i = 0; i < 3; i++) {
            Collections.sort(hands.get(i), new Comparator<Card>() {
                @Override
                public int compare(Card o1, Card o2) {
                    return o1.rank - o2.rank;
                }
            });

        }

        System.out.println("第一个人的牌"+hand1);
        System.out.println("第二个人的牌"+hand2);
        System.out.println("第三个人的牌"+hand3);
    }
}


















